package org.linlinjava.litemall.wx.web;

import lombok.extern.java.Log;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.WxMemberOrderService;
import org.linlinjava.litemall.wx.service.WxUserMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author piao
 */
@RestController
@RequestMapping("/wx/memberOrder")
public class WxMemberOrderController {
    @Autowired
    private WxMemberOrderService wxMemberOrderService;

    /**
     * 提交 支付会员/支付押金 订单
     * @param userId
     * @param body
     * @return
     */
    @PostMapping("/submitOrder")
    public Object submitOrder(@LoginUser Integer userId, @RequestBody String body) {
        return wxMemberOrderService.submitOrder(userId,body);
    }



    /**
     * 申请退押金
     * @param userId
     * @param memberOrderId
     * @return
     */
    @PostMapping("/applyRefund")
    public Object applyRefund(@LoginUser Integer userId,@RequestBody Integer memberOrderId) {
        if (userId == null) {
            return ResponseUtil.unlogin();
        }
        return wxMemberOrderService.applyRefund(userId, memberOrderId);
    }

    @GetMapping("/getDepositOrder")
    public Object getDepositOrder(@LoginUser Integer userId) {
        if (userId == null) {
            return ResponseUtil.unlogin();
        }
        return ResponseUtil.ok(wxMemberOrderService.getDepositOrder(userId));
    }

    /**
     * 获取押金状态
     * @param userId
     * @return 0：未交押金，1：待支付，2：已支付 ，3：申请退款，4：已退款
     */
    @GetMapping("/getDepositStatus")
    public Object getDepositStatus(@LoginUser Integer userId) {
        if (userId == null) {
            return ResponseUtil.unlogin();
        }
        return ResponseUtil.ok(wxMemberOrderService.getDepositStatus(userId));
    }

}
